package b3.widget.mail
{
	import b3.config.*;
	import b3.model.*;
	import b3.util.*;
	import b3.net.*;
	
	import flash.display.Sprite;
	import flash.text.*;
	import flash.filters.*;

	public class ObjectSlot extends Sprite
	{
		public var obj:Obj;
		private var objectSprite:Sprite;
		
		public function ObjectSlot()
		{
			super();
			//背景框
			var ObjectSlotBgr:Class = ResourceHelper.getInstance().getClassByName("ObjectSlotBgr");
			var objectSlotBgr:Sprite = new ObjectSlotBgr();
			addChild(objectSlotBgr);
		}
		
		public function addOjbect(obj:Obj):void
		{
			removeObj();
			this.obj = obj;
			objectSprite = new Sprite();
			var objectConfig:ObjConfig = Config.objConfigs[obj.objectIndex];
			var ObjBgr:Class = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage[0]);
			var objectBgr:Sprite = new ObjBgr();
			objectBgr.x = (this.width - objectBgr.width) / 2;
			objectBgr.y = (this.height - objectBgr.height ) / 2;
			objectSprite.addChild(objectBgr);
			var numText:TextField = new TextField();
			numText.selectable = false;
        	numText.autoSize = TextFieldAutoSize.RIGHT;
    		numText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x0088FF, true);
			numText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			numText.x = this.width - 10;
			numText.text = BFont.formatNumWithComa(obj.objectNum);
			objectSprite.addChild(numText);
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
    		titleText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x0088FF, true);
			titleText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleText.x = this.width / 2;
			titleText.y = 45;
			titleText.text = objectConfig.name;
			objectSprite.addChild(titleText);
			addChild(objectSprite);
		}
		
		public function removeObj():void
		{
			this.obj = null;
			if (objectSprite != null && objectSprite.parent != null)
			{
				removeChild(objectSprite);
			}
		}
	}
}